package com.ln.第一遍1027.demo005;

import java.lang.reflect.Method;

/**
 * @author Ln
 * @version 终极版
 * @date 2022/10/27 16:46
 */
public class Test005 {
    public static void main(String[] args) throws Exception{
        Class<Pig> pigClass = Pig.class;
        Method ha = pigClass.getDeclaredMethod("ha");
        Pig pig = pigClass.newInstance();
        Object invoke = ha.invoke(pig);
        System.out.println("invoke = " + invoke);

        Method he = pigClass.getDeclaredMethod("he", String.class, int.class);
        Object o = he.invoke(pig, "佩奇", 2);
        System.out.println("o = " + o);

    }
}
class Person{
    public void show(){
        System.out.println("人的show方法");
    }
    private void hand(){
        System.out.println("人的hand方法");
    }
}
class Pig extends Person {
    public void ha(){
        System.out.println("猪的ha方法");
    }
    public String he(String name,int age){
        System.out.println("猪的he方法");
        return "你好世界";
    }
}
